from django.shortcuts import render, redirect
from django.http import HttpResponse

# 后台管理首页视图
def backend_dashboard(request):
    return render(request, 'backend/dashboard.html', {'title': '后台管理'})

# 收银台设置视图
def cashier_settings(request):
    if request.method == 'POST':
        # 处理表单提交
        cashier_name = request.POST.get('cashier_name')
        printer = request.POST.get('printer')
        currency_format = request.POST.get('currency_format')
        
        # 这里可以添加保存设置的逻辑
        print(f'保存收银台设置: 收银员={cashier_name}, 打印机={printer}, 货币格式={currency_format}')
        
        return redirect('backend:cashier_settings')
    
    # 模拟数据 - 实际应用中应该从数据库获取
    settings = {
        'cashier_name': '张三',
        'printer': '收据打印机1',
        'currency_format': '¥ #,##0.00'
    }
    
    return render(request, 'cashier/CashierSettingsScreen.html', {
        'settings': settings,
        'title': '收银台设置'
    })

# 简单的测试视图
def test_view(request):
    return HttpResponse('后台管理模块测试页面')
